﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace StandaloneSilverlightWoZ.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        const string _settingsFileName = "ActiveStorySettings.slsx";
        protected void Page_Load(object sender, EventArgs e)
        {
            TaskInstructionsLabel.Text = ImportTaskInstructions(); ;
        }

        private String ImportTaskInstructions()
        {
            string filename = _settingsFileName;
            XmlReaderSettings xws = new XmlReaderSettings();
            xws.CloseInput = true;
            XmlReader xr = XmlReader.Create(GetAbsoluteDataPath(filename), xws);
            xr.ReadStartElement(SilverlightSettingsXmlNames.RootElement);

            xr.ReadStartElement(SilverlightSettingsXmlNames.ProjectFileLocationElement);
            xr.ReadContentAsString();
            xr.ReadEndElement();

            xr.ReadStartElement(SilverlightSettingsXmlNames.TaskInstructionsElement);
            string taskInstructions = xr.ReadContentAsString();
            xr.ReadEndElement();

            xr.ReadEndElement();   //End Root Element
            xr.Close();
            return Server.HtmlDecode(taskInstructions);
        }

        protected void ProceedButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("StandaloneSilverlightWoZTestPage.aspx");
        }
        public static string GetAbsoluteDataPath(string filename)
        {
            string physPath=HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath);
            String uri = System.IO.Path.Combine(physPath, @"WoZData\") + filename;
            return uri;
        }

        public static class SilverlightSettingsXmlNames
        {
            public const string RootElement = "SilverlightSettings";
            public const string ProjectFileLocationElement = "ProjectFileLocation";
            public const string TaskInstructionsElement = "TaskInstructions";
        }
    }
}
